home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / Box.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  37.1 KB  |  1,165 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Box.java    1.29 98/08/28
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15.  
  16. package javax.swing;
  17.  
  18. import java.awt.*;
  19. import java.awt.event.*;
  20. import java.beans.PropertyChangeListener;
  21. import java.util.Locale;
  22. import java.io.Serializable;
  23. import javax.accessibility.*;
  24.  
  25. /**
  26.  * A lightweight container 
  27.  * that uses a BoxLayout object as its layout manager.
  28.  * Box provides several class methods
  29.  * that are useful for containers using BoxLayout --
  30.  * even non-Box containers.
  31.  *
  32.  * <p>
  33.  *
  34.  * The Box class can create several kinds
  35.  * of invisible components 
  36.  * that affect layout:
  37.  * glue, struts, and rigid areas.
  38.  * If all the components your Box contains 
  39.  * have a fixed size,
  40.  * you might want to use a glue component
  41.  * (returned by <code>createGlue</code>)
  42.  * to control the components' positions.
  43.  * If you need a fixed amount of space between two components,
  44.  * try using a strut
  45.  * (<code>createHorizontalStrut</code> or <code>createVerticalStrut</code>).
  46.  * If you need an invisible component
  47.  * that always takes up the same amount of space,
  48.  * get it by invoking <code>createRigidArea</code>.
  49.  * <p>
  50.  * <strong>Warning:</strong>
  51.  * Serialized objects of this class will not be compatible with 
  52.  * future Swing releases.  The current serialization support is appropriate
  53.  * for short term storage or RMI between applications running the same
  54.  * version of Swing.  A future release of Swing will provide support for
  55.  * long term persistence.
  56.  *
  57.  * @see BoxLayout
  58.  *
  59.  * @author  Timothy Prinzing
  60.  * @version 1.29 08/28/98
  61.  */
  62. public class Box extends Container implements Accessible {
  63.  
  64.     /**
  65.      * Creates a <code>Box</code> that displays its components
  66.      * along the the specified axis.
  67.      *
  68.      * @param axis  can be either <code>BoxLayout.X_AXIS</code>
  69.      *              (to display components from left to right) or
  70.      *              <code>BoxLayout.Y_AXIS</code>
  71.      *              (to display them from top to bottom)
  72.      * @see #createHorizontalBox
  73.      * @see #createVerticalBox
  74.      */
  75.     public Box(int axis) {
  76.     super();
  77.     super.setLayout(new BoxLayout(this, axis));
  78.     }
  79.  
  80.     /**
  81.      * Creates a <code>Box</code> that displays its components
  82.      * from left to right.
  83.      *
  84.      * @return the box
  85.      */
  86.     public static Box createHorizontalBox() {
  87.     return new Box(BoxLayout.X_AXIS);
  88.     }
  89.  
  90.     /**
  91.      * Creates a <code>Box</code> that displays its components
  92.      * from top to bottom.
  93.      *
  94.      * @return the box
  95.      */
  96.     public static Box createVerticalBox() {
  97.     return new Box(BoxLayout.Y_AXIS);
  98.     }
  99.  
  100.     /**
  101.      * Creates an invisible component that's always the specified size.
  102.      * <!-- WHEN WOULD YOU USE THIS AS OPPOSED TO A STRUT? -->
  103.      *
  104.      * @param d the dimensions of the invisible component
  105.      * @return the component
  106.      * @see #createGlue
  107.      * @see #createHorizontalStrut
  108.      * @see #createVerticalStrut
  109.      */
  110.     public static Component createRigidArea(Dimension d) {
  111.     return new Filler(d, d, d);
  112.     }
  113.  
  114.     /**
  115.      * Creates an invisible, fixed-width component.
  116.      * In a horizontal box, 
  117.      * you typically use this method 
  118.      * to force a certain amount of space between two components.
  119.      * In a vertical box,
  120.      * you might use this method 
  121.      * to force the box to be at least the specified width.
  122.      * The invisible component has no height
  123.      * unless excess space is available,
  124.      * in which case it takes its share of available space,
  125.      * just like any other component that has no maximum height.
  126.      *
  127.      * @param width the width of the invisible component, in pixels >= 0
  128.      * @return the component
  129.      * @see #createVerticalStrut
  130.      * @see #createGlue
  131.      * @see #createRigidArea
  132.      */
  133.     public static Component createHorizontalStrut(int width) {
  134.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  135.     // to date because BoxLayout alignment breaks.
  136.     return new Filler(new Dimension(width,0), new Dimension(width,0), 
  137.               new Dimension(width, Short.MAX_VALUE));
  138.     }
  139.  
  140.     /**
  141.      * Creates an invisible, fixed-height component.
  142.      * In a vertical box, 
  143.      * you typically use this method
  144.      * to force a certain amount of space between two components.
  145.      * In a horizontal box,
  146.      * you might use this method 
  147.      * to force the box to be at least the specified height.
  148.      * The invisible component has no width
  149.      * unless excess space is available,
  150.      * in which case it takes its share of available space,
  151.      * just like any other component that has no maximum width.
  152.      *
  153.      * @param height the height of the invisible component, in pixels >= 0
  154.      * @return the component
  155.      * @see #createHorizontalStrut
  156.      * @see #createGlue
  157.      * @see #createRigidArea
  158.      */
  159.     public static Component createVerticalStrut(int height) {
  160.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  161.     // to date because BoxLayout alignment breaks.
  162.     return new Filler(new Dimension(0,height), new Dimension(0,height), 
  163.               new Dimension(Short.MAX_VALUE, height));
  164.     }
  165.  
  166.     /**
  167.      * Creates an invisible "glue" component 
  168.      * that can be useful in a Box
  169.      * whose visible components have a maximum width
  170.      * (for a horizontal box)
  171.      * or height (for a vertical box).
  172.      * You can think of the glue component
  173.      * as being a gooey substance
  174.      * that expands as much as necessary
  175.      * to fill the space between its neighboring components.
  176.      *
  177.      * <p>
  178.      *
  179.      * For example, suppose you have
  180.      * a horizontal box that contains two fixed-size components.
  181.      * If the box gets extra space,
  182.      * the fixed-size components won't become larger,
  183.      * so where does the extra space go?
  184.      * Without glue,
  185.      * the extra space goes to the right of the second component.
  186.      * If you put glue between the fixed-size components,
  187.      * then the extra space goes there.
  188.      * If you put glue before the first fixed-size component,
  189.      * the extra space goes there,
  190.      * and the fixed-size components are shoved against the right
  191.      * edge of the box.
  192.      * If you put glue before the first fixed-size component
  193.      * and after the second fixed-size component,
  194.      * the fixed-size components are centered in the box.
  195.      *
  196.      * <p>
  197.      *
  198.      * To use glue,
  199.      * call <code>Box.createGlue</code>
  200.      * and add the returned component to a container.
  201.      * The glue component has no minimum or preferred size,
  202.      * so it takes no space unless excess space is available.
  203.      * If excess space is available, 
  204.      * then the glue component takes its share of available
  205.      * horizontal or vertical space,
  206.      * just like any other component that has no maximum width or height.
  207.      *
  208.      * @return the component
  209.      */
  210.     public static Component createGlue() {
  211.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  212.     // to date because BoxLayout alignment breaks.
  213.     return new Filler(new Dimension(0,0), new Dimension(0,0), 
  214.               new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
  215.     }
  216.  
  217.     /**
  218.      * Creates a horizontal glue component.
  219.      *
  220.      * @return the component
  221.      */
  222.     public static Component createHorizontalGlue() {
  223.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  224.     // to date because BoxLayout alignment breaks.
  225.     return new Filler(new Dimension(0,0), new Dimension(0,0), 
  226.               new Dimension(Short.MAX_VALUE, 0));
  227.     }
  228.  
  229.     /**
  230.      * Creates a vertical glue component.
  231.      *
  232.      * @return the component
  233.      */
  234.     public static Component createVerticalGlue() {
  235.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  236.     // to date because BoxLayout alignment breaks.
  237.     return new Filler(new Dimension(0,0), new Dimension(0,0), 
  238.               new Dimension(0, Short.MAX_VALUE));
  239.     }
  240.  
  241.     /**
  242.      * Throws an AWTError, since a Box can use only a BoxLayout.
  243.      *
  244.      * @param l the layout manager to use
  245.      */
  246.     public void setLayout(LayoutManager l) {
  247.     throw new AWTError("Illegal request");
  248.     }
  249.  
  250.  
  251.     /**
  252.      * An implementation of a lightweight component that participates in
  253.      * layout but has no view.
  254.      * <p>
  255.      * <strong>Warning:</strong>
  256.      * Serialized objects of this class will not be compatible with
  257.      * future Swing releases.  The current serialization support is appropriate
  258.      * for short term storage or RMI between applications running the same
  259.      * version of Swing.  A future release of Swing will provide support for
  260.      * long term persistence.
  261.      */
  262.     public static class Filler extends Component implements Accessible {
  263.  
  264.     /**
  265.      * Constructor to create shape with the given size ranges.
  266.      *
  267.      * @param min   Minimum size
  268.      * @param pref  Preferred size
  269.      * @param max   Maximum size
  270.      */
  271.         public Filler(Dimension min, Dimension pref, Dimension max) {
  272.         reqMin = min;
  273.         reqPref = pref;
  274.         reqMax = max;
  275.     }
  276.  
  277.     /**
  278.      * Change the size requests for this shape.  An invalidate() is
  279.      * propagated upward as a result so that layout will eventually
  280.      * happen with using the new sizes.
  281.      *
  282.      * @param min   Value to return for getMinimumSize
  283.      * @param pref  Value to return for getPreferredSize
  284.      * @param max   Value to return for getMaximumSize
  285.      */
  286.         public void changeShape(Dimension min, Dimension pref, Dimension max) {
  287.         reqMin = min;
  288.         reqPref = pref;
  289.         reqMax = max;
  290.         invalidate();
  291.     }
  292.  
  293.     // ---- Component methods ------------------------------------------
  294.  
  295.         /**
  296.          * Returns the minimum size of the component.
  297.          *
  298.          * @return the size
  299.          */
  300.         public Dimension getMinimumSize() {
  301.         return reqMin;
  302.     }
  303.  
  304.         /**
  305.          * Returns the preferred size of the component.
  306.          *
  307.          * @return the size
  308.          */
  309.         public Dimension getPreferredSize() {
  310.         return reqPref;
  311.     }
  312.  
  313.         /**
  314.          * Returns the maximum size of the component.
  315.          *
  316.          * @return the size
  317.          */
  318.         public Dimension getMaximumSize() {
  319.         return reqMax;
  320.     }
  321.  
  322.     // ---- member variables ---------------------------------------
  323.  
  324.         private Dimension reqMin;
  325.         private Dimension reqPref;
  326.         private Dimension reqMax;
  327.  
  328. /////////////////
  329. // Accessibility support for Box$Filler
  330. ////////////////
  331.  
  332.         /**
  333.          * The currently set AccessibleContext object.
  334.          */
  335.         protected AccessibleContext accessibleContext = null;
  336.  
  337.         /**
  338.          * Gets the AccessibleContext associated with this Component.
  339.          * Creates a new context if necessary.
  340.          *
  341.          * @return the AccessibleContext of this Component
  342.          */
  343.         public AccessibleContext getAccessibleContext() {
  344.         if (accessibleContext == null) {
  345.         accessibleContext = new AccessibleBoxFiller();
  346.         }
  347.         return accessibleContext;
  348.         }
  349.  
  350.     protected class AccessibleBoxFiller extends AccessibleContext
  351.         implements Serializable, AccessibleComponent {
  352.  
  353.             // AccessibleContext methods
  354.             //
  355.             /**
  356.              * Gets the role of this object.
  357.              *
  358.              * @return an instance of AccessibleRole describing the role of
  359.              *   the object (AccessibleRole.FILLER)
  360.              * @see AccessibleRole
  361.              */
  362.             public AccessibleRole getAccessibleRole() {
  363.                 return AccessibleRole.FILLER;
  364.             }
  365.  
  366.             /**
  367.              * Gets the state of this object.
  368.              *
  369.              * @return an instance of AccessibleStateSet containing the current 
  370.              *   state set of the object
  371.              * @see AccessibleState
  372.              */
  373.             public AccessibleStateSet getAccessibleStateSet() {
  374.                 return SwingUtilities.getAccessibleStateSet(Filler.this);
  375.             }
  376.     
  377.             /**
  378.              * Get the Accessible parent of this object.  If the parent of this
  379.              * object implements Accessible, this method should simply return
  380.              * getParent().
  381.              *
  382.              * @return the Accessible parent of this object; null if this
  383.              *   object does not have an Accessible parent
  384.              */
  385.             public Accessible getAccessibleParent() {
  386.         if (accessibleParent != null) {
  387.             return accessibleParent;
  388.         } else {
  389.             Container parent = getParent();
  390.             if (parent instanceof Accessible) {
  391.             return (Accessible) parent;
  392.             }
  393.         }
  394.                 return null;
  395.             }
  396.     
  397.             /**
  398.              * Gets the index of this object in its accessible parent. 
  399.              *
  400.              * @return the index of this object in its parent >= 0; -1 if this 
  401.              *   object does not have an accessible parent.
  402.              * @see #getAccessibleParent
  403.              */
  404.             public int getAccessibleIndexInParent() {
  405.                 return SwingUtilities.getAccessibleIndexInParent(Filler.this);
  406.             }
  407.     
  408.             /**
  409.              * Returns the number of accessible children in the object.  If all
  410.              * of the children of this object implement Accessible, then this
  411.              * method should return the number of children of this object.
  412.              *
  413.              * @return the number of accessible children in the object >= 0
  414.              */
  415.             public int getAccessibleChildrenCount() {
  416.                 return SwingUtilities.getAccessibleChildrenCount(Filler.this);
  417.             }
  418.     
  419.             /**
  420.              * Returns the nth Accessible child of the object.  
  421.              *
  422.              * @param i zero-based index of child
  423.              * @return the nth Accessible child of the object, null if none
  424.              */
  425.             public Accessible getAccessibleChild(int i) {
  426.                 return SwingUtilities.getAccessibleChild(Filler.this,i);
  427.             }
  428.         
  429.             /**
  430.              * Returns the locale of this object.
  431.              *
  432.              * @return the locale of this object
  433.              */
  434.             public Locale getLocale() {
  435.                 return Filler.this.getLocale();
  436.             }
  437.     
  438.             /**
  439.              * Gets the AccessibleComponent associated with this object if one
  440.              * exists.  Otherwise return null.
  441.              *
  442.              * @return the component
  443.              */
  444.         public AccessibleComponent getAccessibleComponent() {
  445.         return this;
  446.         }
  447.     
  448.     
  449.             // AccessibleComponent methods
  450.             //
  451.             /**
  452.              * Gets the background color of this object.
  453.              *
  454.              * @return the background color, if supported, of the object; 
  455.              * otherwise, null
  456.              */
  457.             public Color getBackground() {
  458.                 return Filler.this.getBackground();
  459.             }
  460.     
  461.         // NOTE: IN THE NEXT MAJOR RELEASE, isOpaque WILL MIGRATE
  462.         //       TO java.awt.Component -- ADJUST @SEE LINK BELOW.
  463.             /**
  464.              * Sets the background color of this object.
  465.          * (For transparency, see <code>isOpaque</code>.)
  466.              *
  467.              * @param c the new Color for the background, null if none
  468.          * @s JComponent#isOpaque
  469.              */
  470.             public void setBackground(Color c) {
  471.                 Filler.this.setBackground(c);
  472.             }
  473.     
  474.             /**
  475.              * Gets the foreground color of this object.
  476.              *
  477.              * @return the foreground color, if supported, of the object; 
  478.              * otherwise, null
  479.              */
  480.             public Color getForeground() {
  481.                 return Filler.this.getForeground();
  482.             }
  483.     
  484.             /**
  485.              * Sets the foreground color of this object.
  486.              *
  487.              * @param c the new Color for the foreground, null if none
  488.              */
  489.             public void setForeground(Color c) {
  490.                 Filler.this.setForeground(c);
  491.             }
  492.     
  493.             /**
  494.              * Gets the Cursor of this object.
  495.              *
  496.              * @return the Cursor, if supported, of the object; otherwise, null
  497.              */
  498.             public Cursor getCursor() {
  499.                 return Filler.this.getCursor();
  500.             }
  501.     
  502.             /**
  503.              * Set the Cursor of this object.
  504.              *
  505.              * @param cursor the new Cursor for the object, null if none
  506.              */
  507.             public void setCursor(Cursor cursor) {
  508.                 Filler.this.setCursor(cursor);
  509.             }
  510.     
  511.             /**
  512.              * Gets the Font of this object.
  513.              *
  514.              * @return the Font,if supported, for the object; otherwise, null
  515.              */
  516.             public Font getFont() {
  517.                 return Filler.this.getFont();
  518.             }
  519.     
  520.             /**
  521.              * Sets the Font of this object.
  522.              *
  523.              * @param f the new Font for the object, null if none
  524.              */
  525.             public void setFont(Font f) {
  526.                 Filler.this.setFont(f);
  527.             }
  528.     
  529.             /**
  530.              * Gets the FontMetrics of this object.
  531.              *
  532.              * @param f the Font, null if none
  533.              * @return the FontMetrics, if supported, the object;
  534.              *   otherwise, null
  535.              * @see getFont
  536.              */
  537.             public FontMetrics getFontMetrics(Font f) {
  538.                 return Filler.this.getFontMetrics(f);
  539.             }
  540.     
  541.             /**
  542.              * Determines if the object is enabled.
  543.              *
  544.              * @return true if object is enabled; otherwise, false
  545.              */
  546.             public boolean isEnabled() {
  547.                 return Filler.this.isEnabled();
  548.             }
  549.     
  550.             /**
  551.              * Sets the enabled state of the object.
  552.              *
  553.              * @param b if true, enables this object; otherwise, disables it 
  554.              */
  555.             public void setEnabled(boolean b) {
  556.         boolean old = Filler.this.isEnabled();
  557.         Filler.this.setEnabled(b);
  558.         if (b != old) {
  559.             if (accessibleContext != null) {
  560.             if (b) {
  561.                 accessibleContext.firePropertyChange(
  562.                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  563.                     null, AccessibleState.ENABLED);
  564.             } else {
  565.                 accessibleContext.firePropertyChange(
  566.                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  567.                     AccessibleState.ENABLED, null);
  568.             }
  569.             }
  570.         }
  571.             }
  572.             
  573.             /**
  574.              * Determines if the object is visible.  Note: this means that the
  575.              * object intends to be visible; however, it may not in fact be
  576.              * showing on the screen because one of the objects that this object
  577.              * is contained by is not visible.  To determine if an object is
  578.              * showing on the screen, use isShowing().
  579.              *
  580.              * @return true if object is visible; otherwise, false
  581.              */
  582.             public boolean isVisible() {
  583.                 return Filler.this.isVisible();
  584.             }
  585.     
  586.             /**
  587.              * Sets the visible state of the object.
  588.              *
  589.              * @param b if true, shows this object; otherwise, hides it 
  590.              */
  591.             public void setVisible(boolean b) {
  592.         boolean old = Filler.this.isVisible();
  593.         Filler.this.setVisible(b);
  594.         if (b != old) {
  595.             if (accessibleContext != null) {
  596.             if (b) {
  597.                 accessibleContext.firePropertyChange(
  598.                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  599.                     null, AccessibleState.VISIBLE);
  600.             } else {
  601.                 accessibleContext.firePropertyChange(
  602.                                 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  603.                                 AccessibleState.VISIBLE, null);
  604.             }
  605.             }
  606.         }
  607.             }
  608.     
  609.             /**
  610.              * Determines if the object is showing.  This is determined by
  611.              * checking the visibility of the object and ancestors of the
  612.              * object.  Note: this will return true even if the object is
  613.              * obscured by another (for example, it happens to be
  614.              * underneath a menu that was pulled down).
  615.              *
  616.              * @return true if object is showing; otherwise, false
  617.              */
  618.             public boolean isShowing() {
  619.                 return Filler.this.isShowing();
  620.             }
  621.     
  622.             /** 
  623.              * Checks whether the specified point is within this object's
  624.              * bounds, where the point's x and y coordinates are defined to
  625.              * be relative to the coordinate system of the object. 
  626.              *
  627.              * @param p the Point relative to the coordinate system of
  628.              *   the object
  629.              * @return true if object contains Point; otherwise false
  630.              */
  631.             public boolean contains(Point p) {
  632.                 return Filler.this.contains(p);
  633.             }
  634.         
  635.             /** 
  636.              * Returns the location of the object on the screen.
  637.              *
  638.              * @return location of object on screen; can be null if this object
  639.              * is not on the screen
  640.              */
  641.             public Point getLocationOnScreen() {
  642.         if (Filler.this.isShowing()) {
  643.             return Filler.this.getLocationOnScreen();
  644.         } else {
  645.             return null;
  646.         }
  647.             }
  648.     
  649.             /** 
  650.              * Gets the location of the object relative to the parent in the
  651.              * form of a point specifying the object's top-left corner in
  652.              * the screen's coordinate space.
  653.              *
  654.              * @return An instance of Point representing the top-left corner of 
  655.              * the objects's bounds in the coordinate space of the screen;
  656.              * null if this object or its parent are not on the screen
  657.              */
  658.             public Point getLocation() {
  659.                 return Filler.this.getLocation();
  660.             }
  661.     
  662.             /** 
  663.              * Sets the location of the object relative to the parent.
  664.              *
  665.              * @param p the location to be set
  666.              */
  667.             public void setLocation(Point p) {
  668.                 Filler.this.setLocation(p);
  669.             }
  670.     
  671.             /** 
  672.              * Gets the bounds of this object in the form of a Rectangle
  673.              * object.  The bounds specify this object's width, height,
  674.              * and location relative to its parent. 
  675.              *
  676.              * @return A rectangle indicating this component's bounds; null if 
  677.              * this object is not on the screen.
  678.              */
  679.             public Rectangle getBounds() {
  680.                 return Filler.this.getBounds();
  681.             }
  682.     
  683.             /** 
  684.              * Sets the bounds of this object in the form of a Rectangle
  685.              * object.  The bounds specify this object's width, height,
  686.              * and location relative to its parent.
  687.              *      
  688.              * @param r a rectangle indicating this component's bounds
  689.              */
  690.             public void setBounds(Rectangle r) {
  691.                 Filler.this.setBounds(r);
  692.             }
  693.     
  694.             /** 
  695.              * Returns the size of this object in the form of a Dimension
  696.              * object.  The height field of the Dimension object contains
  697.              * this objects's height, and the width field of the Dimension
  698.              * object contains this object's width. 
  699.              *
  700.              * @return A Dimension object that indicates the size of this 
  701.              * component; null if this object is not on the screen
  702.              */
  703.             public Dimension getSize() {
  704.                 return Filler.this.getSize();
  705.             }
  706.     
  707.             /** 
  708.              * Resizes this object.
  709.              *      
  710.              * @param d - The dimension specifying the new size of the object. 
  711.              */
  712.             public void setSize(Dimension d) {
  713.                 Filler.this.setSize(d);
  714.             }
  715.     
  716.             /**
  717.              * Returns the Accessible child, if one exists, contained at the
  718.              * local coordinate Point.
  719.              *
  720.              * @param p The point defining the top-left corner of the
  721.              * Accessible, given in the coordinate space of the object's 
  722.          * parent. 
  723.              * @return the Accessible, if it exists, at the specified location; 
  724.              *   else null
  725.              */
  726.             public Accessible getAccessibleAt(Point p) {
  727.                 return SwingUtilities.getAccessibleAt(Filler.this,p);
  728.             }
  729.     
  730.             /**
  731.              * Returns whether this object can accept focus or not.
  732.              *
  733.              * @return true if object can accept focus; otherwise false
  734.              */
  735.             public boolean isFocusTraversable() {
  736.                 return Filler.this.isFocusTraversable();
  737.             }
  738.     
  739.             /**
  740.              * Requests focus for this object.
  741.              */
  742.             public void requestFocus() {
  743.                 Filler.this.requestFocus();
  744.             }
  745.     
  746.             /**
  747.              * Adds the specified listener to receive focus events from this 
  748.              * component. 
  749.              *
  750.              * @param l the focus listener
  751.              */
  752.             public void addFocusListener(FocusListener l) {
  753.                 Filler.this.addFocusListener(l);
  754.             }
  755.     
  756.             /**
  757.              * Removes the specified listener so it no longer receives focus 
  758.              * events from this component.
  759.              *
  760.              * @param l the focus listener
  761.              */
  762.             public void removeFocusListener(FocusListener l) {
  763.                 Filler.this.removeFocusListener(l);
  764.             }
  765.         }
  766.     }
  767.  
  768. /////////////////
  769. // Accessibility support for Box
  770. ////////////////
  771.  
  772.     /**
  773.      * The currently set AccessibleContext object.
  774.      */
  775.     protected AccessibleContext accessibleContext = null;
  776.  
  777.     /**
  778.      * Get the AccessibleContext associated with this JComponent.
  779.      * Creates a new context if necessary.
  780.      *
  781.      * @return the AccessibleContext of this JComponent
  782.      */
  783.     public AccessibleContext getAccessibleContext() {
  784.     if (accessibleContext == null) {
  785.         accessibleContext = new AccessibleBox();
  786.     }
  787.     return accessibleContext;
  788.     }
  789.  
  790.     protected class AccessibleBox extends AccessibleContext
  791.     implements Serializable, AccessibleComponent {
  792.  
  793.         // AccessibleContext methods
  794.         //
  795.         /**
  796.          * Gets the role of this object.
  797.          *
  798.          * @return an instance of AccessibleRole describing the role of the 
  799.      *   object (AccessibleRole.FILLER)
  800.          * @see AccessibleRole
  801.          */
  802.         public AccessibleRole getAccessibleRole() {
  803.             return AccessibleRole.FILLER;
  804.         }
  805.  
  806.         /**
  807.          * Gets the state of this object.
  808.          *
  809.          * @return an instance of AccessibleStateSet containing the current 
  810.      * state set of the object
  811.          * @see AccessibleState
  812.          */
  813.         public AccessibleStateSet getAccessibleStateSet() {
  814.         return SwingUtilities.getAccessibleStateSet(Box.this);
  815.         }
  816.  
  817.         /**
  818.          * Gets the Accessible parent of this object.  If the parent of this
  819.          * object implements Accessible, this method should simply return
  820.          * getParent().
  821.          *
  822.          * @return the Accessible parent of this object -- can be null if this
  823.          *   object does not have an Accessible parent
  824.          */
  825.         public Accessible getAccessibleParent() {
  826.             Container parent = getParent();
  827.             if (parent instanceof Accessible) {
  828.                 return (Accessible) parent;
  829.             } else {
  830.                 return null;
  831.             }
  832.         }
  833.  
  834.         /**
  835.          * Gets the index of this object in its accessible parent. 
  836.          *
  837.          * @return the index of this object in its parent >= 0; -1 if this 
  838.          *   object does not have an accessible parent.
  839.          * @see #getAccessibleParent
  840.          */
  841.         public int getAccessibleIndexInParent() {
  842.         return SwingUtilities.getAccessibleIndexInParent(Box.this);
  843.         }
  844.  
  845.         /**
  846.          * Returns the number of accessible children in the object.  If all
  847.          * of the children of this object implement Accessible, then this
  848.          * method should return the number of children of this object.
  849.          *
  850.          * @return the number of accessible children in the object >= 0.
  851.          */
  852.         public int getAccessibleChildrenCount() {
  853.         return SwingUtilities.getAccessibleChildrenCount(Box.this);
  854.         }
  855.  
  856.         /**
  857.          * Return the nth Accessible child of the object.  
  858.          *
  859.          * @param i zero-based index of child
  860.          * @return the nth Accessible child of the object, or null
  861.          */
  862.         public Accessible getAccessibleChild(int i) {
  863.             return SwingUtilities.getAccessibleChild(Box.this,i);
  864.         }
  865.  
  866.         /**
  867.          * Returns the locale of this object.
  868.      *
  869.          * @return the locale of this object
  870.          */
  871.         public Locale getLocale() {
  872.             return Box.this.getLocale();
  873.         }
  874.  
  875.         /**
  876.          * Gets the AccessibleComponent associated with this object if one
  877.          * exists.  Otherwise return null.
  878.          *
  879.          * @return the component
  880.          */
  881.     public AccessibleComponent getAccessibleComponent() {
  882.         return this;
  883.     }
  884.  
  885.  
  886.         // AccessibleComponent methods
  887.         //
  888.         /**
  889.          * Gets the background color of this object.
  890.          *
  891.          * @return the background color, if supported, of the object; 
  892.          * otherwise, null
  893.          */
  894.         public Color getBackground() {
  895.         return Box.this.getBackground();
  896.     }
  897.  
  898.         /**
  899.          * Sets the background color of this object.
  900.          *
  901.          * @param c the new Color for the background, null if none
  902.          */
  903.         public void setBackground(Color c) {
  904.         Box.this.setBackground(c);
  905.     }
  906.  
  907.         /**
  908.          * Gets the foreground color of this object.
  909.          *
  910.          * @return the foreground color, if supported, of the object; 
  911.          *   otherwise, null
  912.          */
  913.         public Color getForeground() {
  914.         return Box.this.getForeground();
  915.     }
  916.  
  917.         /**
  918.          * Sets the foreground color of this object.
  919.          *
  920.          * @param c the new Color for the foreground, null if none
  921.          */
  922.         public void setForeground(Color c) {
  923.         Box.this.setForeground(c);
  924.     }
  925.  
  926.         /**
  927.          * Gets the Cursor of this object.
  928.          *
  929.          * @return the Cursor, if supported, of the object; otherwise, null
  930.          */
  931.         public Cursor getCursor() {
  932.         return Box.this.getCursor();
  933.     }
  934.  
  935.         /**
  936.          * Sets the Cursor of this object.
  937.          *
  938.          * @param cursor the new Cursor for the object, null if none
  939.          */
  940.         public void setCursor(Cursor cursor) {
  941.         Box.this.setCursor(cursor);
  942.     }
  943.  
  944.         /**
  945.          * Gets the Font of this object.
  946.          *
  947.          * @return the Font,if supported, for the object; otherwise, null
  948.          */
  949.         public Font getFont() {
  950.         return Box.this.getFont();
  951.     }
  952.  
  953.         /**
  954.          * Sets the Font of this object.
  955.          *
  956.          * @param f the new Font for the object, null if none
  957.          */
  958.         public void setFont(Font f) {
  959.         Box.this.setFont(f);
  960.     }
  961.  
  962.         /**
  963.          * Gets the FontMetrics of this object.
  964.          *
  965.          * @param f the Font
  966.          * @return the FontMetrics, if supported, the object; otherwise, null
  967.          * @see getFont
  968.          */
  969.         public FontMetrics getFontMetrics(Font f) {
  970.         return Box.this.getFontMetrics(f);
  971.     }
  972.  
  973.         /**
  974.          * Determines if the object is enabled.
  975.          *
  976.          * @return true if object is enabled; otherwise, false
  977.          */
  978.         public boolean isEnabled() {
  979.         return Box.this.isEnabled();
  980.     }
  981.  
  982.         /**
  983.          * Sets the enabled state of the object.
  984.          *
  985.          * @param b if true, enables this object; otherwise, disables it 
  986.          */
  987.         public void setEnabled(boolean b) {
  988.         Box.this.setEnabled(b);
  989.     }
  990.     
  991.         /**
  992.          * Determines if the object is visible.  Note: this means that the
  993.          * object intends to be visible; however, it may not in fact be
  994.          * showing on the screen because one of the objects that this object
  995.          * is contained by is not visible.  To determine if an object is
  996.          * showing on the screen, use isShowing().
  997.          *
  998.          * @return true if object is visible; otherwise, false
  999.          */
  1000.         public boolean isVisible() {
  1001.         return Box.this.isVisible();
  1002.     }
  1003.  
  1004.         /**
  1005.          * Sets the visible state of the object.
  1006.          *
  1007.          * @param b if true, shows this object; otherwise, hides it 
  1008.          */
  1009.         public void setVisible(boolean b) {
  1010.         Box.this.setVisible(b);
  1011.     }
  1012.  
  1013.         /**
  1014.          * Determines if the object is showing.  This is determined by checking
  1015.          * the visibility of the object and ancestors of the object.  Note: 
  1016.      * this will return true even if the object is obscured by another 
  1017.      * (for example, it happens to be underneath a menu that was pulled 
  1018.      * down).
  1019.          *
  1020.          * @return true if object is showing; otherwise, false
  1021.          */
  1022.         public boolean isShowing() {
  1023.         return Box.this.isShowing();
  1024.     }
  1025.  
  1026.         /** 
  1027.          * Checks whether the specified point is within this object's bounds,
  1028.          * where the point's x and y coordinates are defined to be relative to 
  1029.      * the coordinate system of the object. 
  1030.          *
  1031.          * @param p the Point relative to the coordinate system of the object
  1032.          * @return true if object contains Point; otherwise false
  1033.          */
  1034.         public boolean contains(Point p) {
  1035.         return Box.this.contains(p);
  1036.     }
  1037.     
  1038.         /** 
  1039.          * Returns the location of the object on the screen.
  1040.          *
  1041.          * @return location of object on screen -- can be null if this object
  1042.          * is not on the screen
  1043.          */
  1044.         public Point getLocationOnScreen() {
  1045.         return Box.this.getLocationOnScreen();
  1046.     }
  1047.  
  1048.         /** 
  1049.          * Gets the location of the object relative to the parent in the form 
  1050.          * of a point specifying the object's top-left corner in the screen's 
  1051.          * coordinate space.
  1052.          *
  1053.          * @return An instance of Point representing the top-left corner of 
  1054.      *   the objects's bounds in the coordinate space of the screen; null if
  1055.          *   this object or its parent are not on the screen
  1056.          */
  1057.     public Point getLocation() {
  1058.         return Box.this.getLocation();
  1059.     }
  1060.  
  1061.         /** 
  1062.          * Sets the location of the object relative to the parent.
  1063.          *
  1064.          * @param p the location to be set
  1065.          */
  1066.         public void setLocation(Point p) {
  1067.         Box.this.setLocation(p);
  1068.     }
  1069.  
  1070.         /** 
  1071.          * Gets the bounds of this object in the form of a Rectangle object. 
  1072.          * The bounds specify this object's width, height, and location
  1073.          * relative to its parent. 
  1074.          *
  1075.          * @return A rectangle indicating this component's bounds; null if 
  1076.      * this object is not on the screen.
  1077.          */
  1078.         public Rectangle getBounds() {
  1079.         return Box.this.getBounds();
  1080.     }
  1081.  
  1082.         /** 
  1083.          * Sets the bounds of this object in the form of a Rectangle object. 
  1084.          * The bounds specify this object's width, height, and location
  1085.          * relative to its parent.
  1086.          *    
  1087.          * @param r a rectangle indicating this component's bounds
  1088.          */
  1089.         public void setBounds(Rectangle r) {
  1090.         Box.this.setBounds(r);
  1091.     }
  1092.  
  1093.         /** 
  1094.          * Returns the size of this object in the form of a Dimension object. 
  1095.          * The height field of the Dimension object contains this objects's
  1096.          * height, and the width field of the Dimension object contains this 
  1097.      * object's width. 
  1098.          *
  1099.          * @return A Dimension object that indicates the size of this 
  1100.      *   component; null if this object is not on the screen
  1101.          */
  1102.         public Dimension getSize() {
  1103.         return Box.this.getSize();
  1104.     }
  1105.  
  1106.         /** 
  1107.          * Resizes this object.
  1108.          *    
  1109.          * @param d - The dimension specifying the new size of the object. 
  1110.          */
  1111.         public void setSize(Dimension d) {
  1112.         Box.this.setSize(d);
  1113.     }
  1114.  
  1115.         /**
  1116.          * Returns the Accessible child, if one exists, contained at the local
  1117.      * coordinate Point.
  1118.          *
  1119.          * @param p The point defining the top-left corner of the Accessible, 
  1120.      *   given in the coordinate space of the object's parent. 
  1121.          * @return the Accessible, if it exists, at the specified location; 
  1122.      *   else null
  1123.          */
  1124.         public Accessible getAccessibleAt(Point p) {
  1125.         return SwingUtilities.getAccessibleAt(Box.this,p);
  1126.     }
  1127.  
  1128.         /**
  1129.          * Determines whether this object can accept focus or not.
  1130.          *
  1131.          * @return true if object can accept focus; otherwise false
  1132.          */
  1133.         public boolean isFocusTraversable() {
  1134.         return Box.this.isFocusTraversable();
  1135.     }
  1136.  
  1137.         /**
  1138.          * Requests focus for this object.
  1139.          */
  1140.         public void requestFocus() {
  1141.         Box.this.requestFocus();
  1142.         }
  1143.  
  1144.         /**
  1145.          * Adds the specified focus listener to receive focus events from this 
  1146.          * component. 
  1147.          *
  1148.          * @param l the focus listener
  1149.          */
  1150.         public void addFocusListener(FocusListener l) {
  1151.         Box.this.addFocusListener(l);
  1152.     }
  1153.  
  1154.         /**
  1155.          * Removes the specified focus listener so it no longer receives focus 
  1156.          * events from this component.
  1157.          *
  1158.          * @param l the focus listener
  1159.          */
  1160.         public void removeFocusListener(FocusListener l) {
  1161.         Box.this.removeFocusListener(l);
  1162.     }
  1163.     } // inner class AccessibleBox
  1164. }
  1165.